import type { ToastOptions } from 'wot-design-uni/components/wd-toast/types';

type ToastType = 'success' | 'error' | 'info' | 'warning' | 'loading' | 'close';

/**
 * 全局 toast 事件
 */
class Toast {
  private emitToast(type: ToastType, data?: ToastOptions | string): void {
    uni.$emit('toast', { type, data });
  }

  success(data: ToastOptions | string): void {
    this.emitToast('success', data);
  }

  error(data: ToastOptions | string): void {
    this.emitToast('error', data);
  }

  warning(data: ToastOptions | string): void {
    this.emitToast('warning', data);
  }

  loading(data: ToastOptions | string): void {
    this.emitToast('loading', data);
  }

  hide(): void {
    this.emitToast('close');
  }
}

export const toast = new Toast();
